<!--内容开始-->
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <!--顶部提示开始-->
            <div class="col-12 alert alert-warning alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <p>
                    {if $info}
                    字段修改时会构建SQL语句来修改数据表的字段，如不想修改可勾选<修改表字段>为[否];
                    {else /}
                    1、数据表中不存在要添加的字段时会自动创建该字段并添加到字段管理中;<br>
                    2、数据表中已存在要添加的字段时仅会插入到字段管理中;
                    {/if}
                </p>
            </div>
            <!--顶部提示结束-->
            {if $layer == false}
            <div class="col-12 callout search">
                <form action="">
                    <a class="btn btn-flat btn-primary" href="{:url('index')}"><i class="fa fa-list-ul m-r-10"></i>查看全部</a>
                    <a class="btn btn-flat btn-success f_r" onclick="javascript :history.back(-1)"><i class="fa fa-undo m-r-10"></i>返 回</a>
                </form>
            </div>
            {/if}
            <!--数据表开始-->
            {if $info}
            <form class="col-12 form_builder" method="post" action="{:url('editPost')}" submit_confirm>
                <input type="hidden" name="id" value="{$info.id}"/>
                <input type="hidden" name="old_field" value="{$info.field}"/>
            {else /}
            <form class="col-12 form_builder" method="post" action="{:url('addPost')}" submit_confirm>
            {/if}
                    <input type="hidden" name="module_id" value="{$info ? $info.module_id : $module_id}"/>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">所属模块</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <select id="module_id" name="module_id" class="form-control">
                                <option value=''>请选择</option>
                                {volist name="modules" id="module"}
                                <option value="{$module.id}" {$module_id == $module.id ? 'selected="selected"' : ''} >{$module.module_name} - [ {$module.table_name} ]</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 字段所属的模块/表
                            </small>
                        </div>
                    </div>
                    <!---->
                    {if $groups}
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">所属分组</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <select id="group_id" name="group_id" class="form-control">
                                <option value=''>请选择</option>
                                {volist name="groups" id="group"}
                                <option value="{$group.id}" {$info.group_id == $group.id ? 'selected="selected"' : ''} >{$group.group_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 字段所属分组
                            </small>
                        </div>
                    </div>
                    {/if}
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">字段类型</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <select id="type" name="type" class="form-control">
                                <option value=''>请选择字段类型</option>
                                <option value="text" {if $info}{$info.type == 'text' ? 'selected="selected"' : ''}{/if}>单行文本</option>
                                <option value="textarea" {if $info}{$info.type == 'textarea' ? 'selected="selected"' : ''}{/if}>多行文本</option>
                                <option value="radio" {if $info}{$info.type == 'radio' ? 'selected="selected"' : ''}{/if}>单选按钮</option>
                                <option value="checkbox" {if $info}{$info.type == 'checkbox' ? 'selected="selected"' : ''}{/if}>多选按钮</option>
                                <option value="date" {if $info}{$info.type == 'date' ? 'selected="selected"' : ''}{/if}>日期</option>
                                <option value="time" {if $info}{$info.type == 'time' ? 'selected="selected"' : ''}{/if}>时间</option>
                                <option value="datetime" {if $info}{$info.type == 'datetime' ? 'selected="selected"' : ''}{/if}>日期时间</option>
                                <option value="daterange" {if $info}{$info.type == 'daterange' ? 'selected="selected"' : ''}{/if}>日期范围</option>
                                <option value="tag" {if $info}{$info.type == 'tag' ? 'selected="selected"' : ''}{/if}>标签</option>
                                <option value="number" {if $info}{$info.type == 'number' ? 'selected="selected"' : ''}{/if}>数字</option>
                                <option value="password" {if $info}{$info.type == 'password' ? 'selected="selected"' : ''}{/if}>密码</option>
                                <option value="select" {if $info}{$info.type == 'select' ? 'selected="selected"' : ''}{/if}>普通下拉菜单</option>
                                <option value="select2" {if $info}{$info.type == 'select2' ? 'selected="selected"' : ''}{/if}>高级下拉菜单</option>
                                <option value="image" {if $info}{$info.type == 'image' ? 'selected="selected"' : ''}{/if}>单张图片</option>
                                <option value="images" {if $info}{$info.type == 'images' ? 'selected="selected"' : ''}{/if}>多张图片</option>
                                <option value="file" {if $info}{$info.type == 'file' ? 'selected="selected"' : ''}{/if}>单文件上传</option>
                                <option value="files" {if $info}{$info.type == 'files' ? 'selected="selected"' : ''}{/if}>多文件上传</option>
                                <option value="editor" {if $info}{$info.type == 'editor' ? 'selected="selected"' : ''}{/if}>编辑器</option>
                                <option value="hidden" {if $info}{$info.type == 'hidden' ? 'selected="selected"' : ''}{/if}>隐藏域</option>
                                <option value="color" {if $info}{$info.type == 'color' ? 'selected="selected"' : ''}{/if}>取色器</option>
                            </select>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">字段名称</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <input type="text" name="field" class="form-control" placeholder="字段英文名称，如 title"
                                   value="{$info.field?$info.field:''}">
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 注意不要包含空格，建议全部小写，通过_分割，如 user_name, goods_price
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">字段别名</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <input type="text" name="name" class="form-control" placeholder="字段中文名称，如 标题"
                                   value="{$info.name?$info.name:''}">
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 建议不超过4个汉字
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">提示信息</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <input type="text" name="tips" class="form-control" placeholder="字段右侧提示信息"
                                   value="{$info.tips?$info.tips:''}">
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 新增/修改页面字段右侧的提示信息
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">是否必填</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <div class="dd_radio_lable_left">
                                <label class="dd_radio_lable">
                                    <input type="radio" name="required" value="1" class="dd_radio"
                                           {if $info}{$info.required==1?'checked':''}{/if}><span>是</span>
                                </label>
                                <label class="dd_radio_lable">
                                    <input type="radio" name="required" value="0" class="dd_radio"
                                           {if $info}{$info.required==0?'checked':''}{else /}checked{/if}><span>否</span>
                                </label>
                            </div>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">字段展示</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <div class="dd_radio_lable_left">
                                <label class="dd_radio_lable">
                                    <input type="checkbox" name="is_list" value="1" class="dd_radio" {if $info}{$info.is_list===0?'':'checked'}{else /}checked{/if}><span>列表</span></label>
                                <label class="dd_radio_lable">
                                    <input type="checkbox" name="is_add" value="1" class="dd_radio" {if $info}{$info.is_add===0?'':'checked'}{else /}checked{/if}><span>添加</span></label>
                                <label class="dd_radio_lable">
                                    <input type="checkbox" name="is_edit" value="1" class="dd_radio" {if $info}{$info.is_edit===0?'':'checked'}{else /}checked{/if}><span>修改</span></label>
                                <label class="dd_radio_lable">
                                    <input type="checkbox" name="is_search" value="1" class="dd_radio" {if $info}{$info.is_search===0?'':'checked'}{else /}checked{/if}><span>搜索</span></label>
                                <label class="dd_radio_lable">
                                    <input type="checkbox" name="is_sort" value="1" class="dd_radio" {if $info}{$info.is_sort===0?'':'checked'}{else /}checked{/if}><span>排序</span></label>
                            </div>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 设置字段的使用场景
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">搜索类型</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <input type="text" name="search_type" class="form-control" placeholder="请填写搜索类型"
                                   value="{$info.search_type?$info.search_type:'='}">
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 如：=, <>, >, <, LIKE 等表达式，如字段可被搜索则必须设置
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">字符长度</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <div class="col-4 p-0 float-left">
                                <input type="text" name="minlength" class="form-control"
                                       value="{$info.minlength?$info.minlength:'0'}">
                            </div>
                            <div class="col-1 p-0 float-left line_height_38 text-center">-</div>
                            <div class="col-4 p-0 float-left">
                                <input type="text" name="maxlength" class="form-control"
                                       value="{$info.maxlength?$info.maxlength:'0'}">
                            </div>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 通常无需配置，系统会自动设置
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">数据源</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <select id="data_source" name="data_source" class="form-control">
                                <option value='0'>字段本身</option>
                                <option value="1" {if $info}{$info.data_source=='1'?'selected="selected"':''}{/if}>系统字典</option>
                                <option value="2" {if $info}{$info.data_source=='2'?'selected="selected"':''}{/if}>模型数据</option>
                            </select>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 通常 select|radio|checkbox 或关联了其他模型时需配置
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">关联模型</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <input type="text" name="relation_model" class="form-control" placeholder="请填写关联的模型"
                                   value="{$info.relation_model?$info.relation_model:''}">
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 只有数据源选择<模型数据>时生效，填写完整的模型名称，如 User
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">展示字段</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <input type="text" name="relation_field" class="form-control" placeholder="请填写关联模型对应的字段"
                                   value="{$info.relation_field?$info.relation_field:''}">
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 只有数据源选择<模型数据>时生效，填写完整的字段名称，如 type_name
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">字典类型</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <select id="dict_code" name="dict_code" class="form-control">
                                <option value=''>请选择</option>
                                {volist name="dictTypes" id="dictTypes"}
                                <option value="{$dictTypes.id}" {if $info}{$info.dict_code == $dictTypes.id ? 'selected="selected"' : ''}{/if}>{$dictTypes.dict_name} - [ {$dictTypes.remark} ]</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 只有数据源选择<系统字典>时生效
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">字段设置</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <div class="dd_radio_lable_left" id="field_setup">
                                <!--ajax调用文件-->
                                <!--ajax调用结束-->
                            </div>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">状态</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <div class="dd_radio_lable_left">
                                {if $info}
                                <label class="dd_radio_lable">
                                    <input type="radio" name="status" value="1" class="dd_radio" {$info.status ?
                                    'checked' : ''}><span>显示</span>
                                </label>
                                <label class="dd_radio_lable">
                                    <input type="radio" name="status" value="0" class="dd_radio" {$info.status ?
                                    '' : 'checked'}><span>隐藏</span>
                                </label>
                                {else /}
                                <label class="dd_radio_lable">
                                    <input type="radio" name="status" value="1" class="dd_radio" checked><span>显示</span>
                                </label>
                                <label class="dd_radio_lable">
                                    <input type="radio" name="status" value="0" class="dd_radio"><span>隐藏</span>
                                </label>
                                {/if}
                            </div>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label is-required">排序</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <input type="text" name="sort" class="form-control" placeholder="请输入排序"
                                   value="{$info.sort ? $info.sort : '50'}">
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 排序为从小到大排序，默认为50
                            </small>
                        </div>
                    </div>
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">字段备注</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <textarea class="form-control" name="remark" rows="3" placeholder="请输入字段备注">{$info.remark|default=''}</textarea>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 字段备注
                            </small>
                        </div>
                    </div>
                    {if $info}
                    <!---->
                    <div class="row dd_input_group no-gutters">
                        <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label">修改表字段</label>
                        <div class="col-9 col-sm-9 col-md-9 col-lg-6 col-xl-4">
                            <div class="dd_radio_lable_left">
                                <label class="dd_radio_lable">
                                    <input type="radio" name="execute_sql" value="1" class="dd_radio" checked><span>是</span>
                                </label>
                                <label class="dd_radio_lable">
                                    <input type="radio" name="execute_sql" value="0" class="dd_radio"><span>否</span>
                                </label>
                            </div>
                        </div>
                        <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-4 col-xl-7 dd_ts">
                            <small class="text-muted">
                                <i class="fa fa-info-circle"></i> 选择是会构建SQL语句来修改数据表的字段，选择否则不修改
                            </small>
                        </div>
                    </div>
                    {/if}
                    <!---->
                    <div class="row dd_input_group form-builder-submit no-gutters {if $layer == true}hide{/if}">
                        <div class="col-10 col-sm-10 col-md-10 col-lg-10 col-xl-11 offset-sm-2 offset-md-2 offset-lg-2 offset-xl-1">
                            <button type="submit" class="btn btn-flat btn-primary ">提 交</button>
                            <button type="button" class="btn btn-flat btn-default"
                                    onclick="javascript :history.back(-1)">返 回
                            </button>
                        </div>
                    </div>
            </form>
            <!--数据表结束-->
        </div>
    </div>
</section>
<!--内容结束-->

<script>
    $(function(){
        // 字段变更时触发
        $("#type").change(function(){
            var type = $(this).val();
            var url = "{:url('changeType')}?isajax=1&moduleId={$module_id}&type=" + type;
            field_setting(type, url);
        });
        // 编辑字段时触发
        {if $info}
        var type  = '{$info.type}';
        var field = '{$info.field}';
        var url   = "{:url('changeType')}?isajax=1&moduleId={$info.module_id}&type=" + type + "&field=" + field;
        field_setting(type, url);
        {/if}

    })
    //选择后变更
    function field_setting(type, url, data) {
        $.ajax({
            type : "POST",
            url  : url,
            data : '',
            beforeSend: function () {
                $('#field_setup').html('<i class="fa fa-spinner fa-spin fa-fw"></i>');
            },
            success: function (msg) {
                $('#field_setup').html(msg);
            }
        });
    }
</script>
